import requests
from bs4 import BeautifulSoup
import pandas as pd

# 获取数据
url = 'https://comment.bilibili.com/355081548.xml'
rq = requests.get(url)
rq.encoding = "utf-8"

# 解析
html = rq.text
soup = BeautifulSoup(html, 'xml')
tmp = soup.select('d')
danmu = [i.text for i in tmp]
data = [i.get('p').split(',') for i in tmp]


# 下载数据
data = pd.DataFrame(data)

data.columns = [['出现时间点', '模式', '字体', '颜色', '发送时间', '弹幕池', '用户ID', 'rowID', '1']]
data['content'] = danmu
print(data.head())
data.to_csv("./content.csv", index=None, encoding='utf-8')



